home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / QuickDraw / QuickDraw™ FX / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-10  |  5.0 KB  |  249 lines  |  [TEXT/KAHL]

  1. /****************************************************************************/
  2. /*                                                                            */
  3. /*    Application:    QuickDraw™ FX                                            */
  4. /*                                                                            */
  5. /*    Description:                                                            */
  6. /*                                                                            */
  7. /*    File:            menu.c                                                    */
  8. /*                                                                            */
  9. /*    Files:            FX.π                                                    */
  10. /*                    FX.π.rsrc                                                */
  11. /*                    FX.h                                                    */
  12. /*                    events.c                                                */
  13. /*                    main.c                                                    */
  14. /*                    menu.c                                                    */
  15. /*                                                                            */
  16. /*    Programmer:        Edgar Lee                                                */
  17. /*    Organization:    Apple Computer, Inc. ©1992                                */
  18. /*    Department:        Developer Technical Support, DTS                        */
  19. /*    Language:        C (Think C version 5.0.2)                                */
  20. /*    Date Created:    5-26-92                                                    */
  21. /*                                                                            */
  22. /****************************************************************************/
  23.  
  24. #include "FX.h"
  25.  
  26. enum {
  27.     appleID = 128,
  28.     fileID = 129,
  29.     exID = 130,
  30.     srcID = 131
  31. };
  32.  
  33. enum {
  34.     quitItem = 1
  35. };
  36.  
  37. #define    WWIDTH        420
  38. #define    WHEIGHT        200
  39.  
  40. #define WLEFT        (((screenBits.bounds.right - screenBits.bounds.left) - WWIDTH) / 2)
  41. #define WTOP        (((screenBits.bounds.bottom - screenBits.bounds.top) - WHEIGHT) / 2)
  42.  
  43. void doAboutBox();
  44. void drawMyString();
  45.  
  46. void setUpMenus()
  47. {
  48.     Handle        menuHandle;
  49.     
  50.     if ((menuHandle = GetNewMBar( 128 )) == nil)
  51.         ExitToShell();
  52.         
  53.     SetMenuBar( menuHandle );
  54.     AddResMenu( GetMenu( appleID ), 'DRVR' );
  55.         
  56.     DrawMenuBar();
  57.     ReleaseResource( menuHandle );
  58. }
  59.  
  60. void adjustMenus()
  61. {
  62.     int        i;
  63.  
  64.     EnableItem( GetMHandle( fileID ), quitItem );
  65.     
  66.     for (i = 1; i <= pixelAverageID; i++)
  67.         setMenuItem( GetMHandle( exID ), i, (i == gCurrentExample / 10) );
  68.     
  69.     setMenuItem( GetMHandle( exID ), customID + 1, (customID == gCurrentExample / 10) );
  70. }
  71.  
  72. void setMenuItem( menu, itemNum, enabled )
  73. MenuHandle    menu;
  74. int            itemNum;
  75. Boolean        enabled;
  76. {
  77.     if (enabled)
  78.         CheckItem( menu, itemNum, true );
  79.     else
  80.         CheckItem( menu, itemNum, false );
  81. }
  82.  
  83. void handleMenu( mSelect )
  84. long mSelect;
  85. {
  86.     int            menuID = HiWord( mSelect );
  87.     int            menuItem = LoWord( mSelect );
  88.     GrafPtr        savePort;
  89.     Str255        name;
  90.     long        ticks;
  91.  
  92.     switch (menuID)
  93.     {
  94.         case appleID:
  95.             if (menuItem == 1)
  96.                 doAboutBox();
  97.             else
  98.             {
  99.                 GetPort( &savePort );
  100.                 GetItem( GetMenu( appleID ), menuItem, name );
  101.                 OpenDeskAcc( name );
  102.                 SetPort( savePort );
  103.             }
  104.             break;
  105.             
  106.         case fileID:
  107.             if (menuItem)
  108.                 ExitToShell();
  109.             break;
  110.             
  111.         case exID:
  112.             if (menuItem == 10)
  113.                 menuItem--;
  114.  
  115.             if (menuItem == gCurrentExample / 10)
  116.                 break;
  117.             
  118.             if (menuItem == 9)
  119.                 resetItems();
  120.                 
  121.             gCurrentExample = (menuItem * 10) + 1;
  122.             drawExampleName();
  123.             drawSourceImage();
  124.             
  125.             ticks = drawFXImage();
  126.             drawTime( ticks );
  127.             drawAllItems();
  128.             break;
  129.             
  130.         case srcID:
  131.             createOffscreen( menuItem );
  132.             drawSourceImage();
  133.             
  134.             ticks = drawFXImage();
  135.             drawTime( ticks );
  136.             break;
  137.     }
  138.     
  139.     HiliteMenu( 0 );
  140. }
  141.  
  142. void doAboutBox()
  143. {
  144.     int                col, row;
  145.     int                width, height;
  146.     WindowPtr        window;
  147.     CIconHandle        cicn;
  148.     Rect            rect;
  149.     RGBColor        color;
  150.  
  151.     cicn = GetCIcon( 128 );
  152.     HPurge( cicn );
  153.  
  154.     SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
  155.     window = NewCWindow( 0L, &rect, "\p", true, plainDBox, (WindowPtr)-1L, false, 0L );                            
  156.     SetPort( window );
  157.         
  158.     TextFont( geneva );
  159.     TextMode( srcOr );
  160.     
  161.     color.red = color.green = color.blue = 8700;
  162.     RGBForeColor( &color );
  163.         
  164.     rect = window->portRect;
  165.     InsetRect( &rect, 1, 1 );
  166.     PaintRect( &rect );
  167.     
  168.     width = 32 * 6;
  169.     height = width;
  170.     
  171.     SetRect( &rect, 3, 3, width + 3, height + 3 );
  172.     PlotCIcon( &rect, cicn );
  173.  
  174.     ForeColor( blackColor );
  175.  
  176.     for (row = 6; row < height; row += 6)
  177.     {
  178.         MoveTo( rect.left, rect.top + row );
  179.         LineTo( rect.left + width, rect.top + row );
  180.     }
  181.     
  182.     for (col = 6; col < width; col += 6)
  183.     {
  184.         MoveTo( rect.left + col, rect.top );
  185.         LineTo( rect.left + col, rect.top + height );
  186.     }
  187.     
  188.     col = width + 15;
  189.     row = 35;
  190.     
  191.     TextFont( times );
  192.     TextSize( 36 );
  193.     
  194.     color.blue = 0xffff;
  195.     color.red = color.green = 0;
  196.     RGBForeColor( &color );    
  197.     drawMyString( col, &row, 30, "\pQuickDraw™" );
  198.     
  199.     color.blue = 0x9fff;
  200.     RGBForeColor( &color );
  201.     drawMyString( col + 45, &row, -5, "\pFX" );
  202.     
  203.     TextFont( geneva );
  204.     TextSize( 9 );
  205.     ForeColor( whiteColor );
  206.     
  207.     col += 10;
  208.     
  209.     drawMyString( col + 115, &row, 25, "\pVersion 1.0" );
  210.     drawMyString( col, &row, 20, "\pBrought to you by Edgar Lee." );
  211.     
  212.     drawMyString( col, &row, 13, "\pFor any suggestions or comments," );
  213.     drawMyString( col, &row, 13, "\pplease write to edgar@apple.com" );
  214.     drawMyString( col, &row, 20, "\por appleLink EDGAR." );
  215.     
  216.     drawMyString( col, &row, 15, "\p© 1992 Apple Computer, Inc." );
  217.     drawMyString( col, &row, 25, "\pAll rights reserved." );
  218.     
  219.     TextFont( times );
  220.     TextSize( 36 );
  221.     
  222.     color.green = 0x8fff;
  223.     color.red = color.blue = 0;
  224.     RGBForeColor( &color );
  225.     drawMyString( col + 125, &row, 0, "\pDTS" );
  226.     
  227.     while (!Button());
  228.     
  229.     DisposeWindow( window );
  230. }
  231.  
  232. void drawMyString( col, row, increment, string )
  233. int        col, *row, increment;
  234. Str255    string;
  235. {
  236.     RGBColor    color;
  237.     
  238.     GetForeColor( &color );
  239.     
  240.     ForeColor( blackColor );
  241.     MoveTo( col + 2, *row + 2 );
  242.     DrawString( string );
  243.     
  244.     RGBForeColor( &color );
  245.     MoveTo( col, *row );
  246.     DrawString( string );
  247.     
  248.     *row += increment;
  249. }